import hashlib
import time

import requests
from fake_useragent import UserAgent



page = 1

total = 0
while True:
    ua = UserAgent()
    _ts = int(time.time() * 1000)
    sign = hashlib.md5(f"tuling{_ts}{page}".encode()).hexdigest()
    url = f'https://mashangpa.com/api/problem-detail/4/data/?page={page}&sign={sign}&_ts={_ts}'
    headers = {
        'cookie':'sessionid=knisj2ex95xlec3gp1rwa8zg5sfpd0wk',
        'user-agent': ua.random,
        'referer':'https://mashangpa.com/problem-detail/4/',
    }
    # print(url)


    content = requests.get(url,headers=headers,timeout=10)

    for e in content.json()['current_array']:
        total += e
    print(f'爬取第{page}页完成,目前总数：{total}')
    if content.json()['pagination']['has_next']:
        page += 1
    else:
        break

print(f'总数：{total}')











